package com.ase.单例模式.volatiles;

/**
 * @author gyhstart
 * @create 2021/3/2 - 16:04
 **/
public class Singleton {
    private static volatile Singleton singleton = null;

    public Singleton() {
        System.out.println("singleton.volatile");
    }

    public static Singleton getInstance() {
        if (singleton == null) {
            synchronized (Singleton.class) {
                if (singleton == null) {
                    singleton = new Singleton();
                }
            }
        }

        return singleton;
    }

    public void Message(){
        System.out.println(Thread.currentThread().getId());
    }
}
